package com.giantlizard.cloud.system.controller;

import com.giantlizard.cloud.base.generics.R;
import com.giantlizard.cloud.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author kangdongwei
* @since 2024-07-28
*/

@RestController
@RequestMapping("/user")
@Api(value = "系统-用户", tags = {"系统-用户"})
public class SysUserController {

    private final SysUserService sysUserService;

    public SysUserController(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    @ApiOperation(value = "根据Id获取单条数据")
    @GetMapping("/{id}")
    public R selectById(@ApiParam(name = "id", required = true, value = "内部id") @PathVariable String id) throws Exception {
        return R.ok(sysUserService.getById(id));
    }

    @ApiOperation(value = "根据Id获取单条数据")
    @GetMapping("/info/{username}")
    public R getUserInfo(@ApiParam(name = "username", required = true, value = "用户名称") @PathVariable String username) throws Exception {
        return R.ok(sysUserService.getUserInfo(username));
    }

    @ApiOperation("获取用户角色")
    @GetMapping("/roles/{userId}")
    public R getRoles(@PathVariable String userId) {
        return R.ok(sysUserService.getRoles(userId));
    }
}
